/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[欢迎加盟知启蒙，一起邂逅框架梦]
 * 
 * https://www.zhiqim.com/gitcan/zhiqim/zhiqim_account.htm
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zhiqim.account.api.connect;

import org.zhiqim.kernel.json.Jsons;

public class WxUserInfo implements IUserInfo
{
    private String json;
    private int accountType;
    
    private String openId;              //普通用户的标识，对当前开发者帐号唯一
    private String nickName;            //普通用户昵称
    private int sex;                    //普通用户性别，1为男性，2为女性
    private String province;            //普通用户个人资料填写的省份
    private String city;                //普通用户个人资料填写的城市
    private String country;             //国家，如中国为CN
    private String headImgurl;          //用户头像，最后一个数值代表正方形头像大小（有0、46、64、96、132数值可选，0代表640*640正方形头像），用户没有头像时该项为空
    private String privilege;           //用户特权信息，json数组，如微信沃卡用户为（chinaunicom）
    private String unionId;             //用户统一标识。针对一个微信开放平台帐号下的应用，同一用户的unionid是唯一的。
    
    public WxUserInfo parse(String json)
    {
        this.json = json;
        this.openId = Jsons.getString(json, "openid");
        this.nickName = Jsons.getString(json, "nickname");
        this.sex = Jsons.getInt(json, "sex");
        this.province = Jsons.getString(json, "province");
        this.city = Jsons.getString(json, "city");
        this.country = Jsons.getString(json, "country");
        this.headImgurl = Jsons.getString(json, "headimgurl");
        this.privilege = Jsons.getString(json, "privilege");
        this.unionId = Jsons.getString(json, "unionid");//开发者最好保存用户unionID信息，以便以后在不同应用中进行用户信息互通。
        
        return this;
    }

    public String getJson()
    {
        return json;
    }

    public String getOpenId()
    {
        return openId;
    }

    public String getNickName()
    {
        return nickName;
    }

    public int getSex()
    {
        return sex;
    }

    public String getProvince()
    {
        return province;
    }

    public String getCity()
    {
        return city;
    }

    public String getCountry()
    {
        return country;
    }

    public String getHeadImgurl()
    {
        return headImgurl;
    }

    public String getPrivilege()
    {
        return privilege;
    }

    public String getUnionId()
    {
        return unionId;
    }
    
    public WxUserInfo setAccountType(int accountType)
    {
        this.accountType = accountType;
        return this;
    }
    
    /*************************************************************************************/
    //实现IUserInfo接口
    /*************************************************************************************/
    
    @Override
    public int getAccountType()
    {
        return accountType;
    }
    
    @Override
    public String getAccountUnion()
    {
        return unionId;
    }

    @Override
    public String getUserAccount()
    {
        return openId;
    }
    
    @Override
    public String getUserNick()
    {
        return nickName;
    }
    
    @Override
    public int getUserSex()
    {
        return sex;
    }

    @Override
    public String getUserAvatar50()
    {
        return headImgurl;
    }
    
    @Override
    public String getUserAvatar100()
    {
        return headImgurl;
    }

    @Override
    public String getUserAvatar150()
    {
        return headImgurl;
    }
}
